﻿using System;

namespace Pfz.Threading.Unsafe
{
	internal sealed class _UnsafeThreadedIteratorFromAction:
		UnsafeThreadedIterator
	{
		private IteratorAction _action;

		/// <summary>
		/// Creates a new instance of this class prepared to run the given animation.
		/// </summary>
		public _UnsafeThreadedIteratorFromAction(IteratorAction action)
		{
			if (action == null)
				throw new ArgumentNullException("action");

			_action = action;
		}

		/// <summary>
		/// Runs the action used to construct this class.
		/// </summary>
		protected override void OnRun()
		{
			_action(base.YieldReturn);
		}
	}
}
